//
//  LSZBigDepartmentVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/30.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZBigDepartmentVC.h"

@interface LSZBigDepartmentVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView * tableViewBigDepartment;

@property(nonatomic,strong)LSZEachAgencyManager * eachAgencyManager;//各个组织的数据
@end

@implementation LSZBigDepartmentVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=YES;
    if([self.specialMark isEqualToString:@"1"]){
        NSLog(@"%@>>>>>>>>>>!",[_UserM id_id]);
        [self getDepartment:[_UserM id_id]];
    }else{
        [self getDepartment:self.id_id];
    }
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden=NO;
}
#pragma mark - 得到所属的部门
-(void)getDepartment :(NSString *)id_id
{
    [LSZRequestDicData getTheDepartmentOfEachAgency:id_id :^(BOOL isOk, NSString * string, LSZEachAgencyManager * manager) {
        if (isOk == YES) {
            self.eachAgencyManager = manager;
            [self.tableViewBigDepartment reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZBigDepartmentVC"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)clickRightBut
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZBigDepartmentVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotificationCenter];
    self.title = self.titleString;
    _tableViewBigDepartment = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth,ScreenHeight) style:UITableViewStyleGrouped];
    _tableViewBigDepartment.delegate = self;
    _tableViewBigDepartment.dataSource = self;
    _tableViewBigDepartment.estimatedRowHeight=0;
    _tableViewBigDepartment.estimatedSectionFooterHeight =0;
    _tableViewBigDepartment.estimatedSectionHeaderHeight =0;
    [_tableViewBigDepartment setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
    [self.view addSubview:_tableViewBigDepartment];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.eachAgencyManager.arrayData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    LSZEachAgencyMg * mg = nil;
    mg = self.eachAgencyManager.arrayData[indexPath.row];
    cell.textLabel.text = mg.name;
    cell.textLabel.font = FONT_(14);
    cell.textLabel.textColor = titleColorLSZ;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZEachAgencyMg * mg = nil;
    mg = self.eachAgencyManager.arrayData[indexPath.row];
    if ([mg.leaf isEqualToString:@"1"]) {
        LSZParentThreeLessonVC * VC= [[LSZParentThreeLessonVC alloc]init];
        VC.id_id = mg.id_id;
        VC.summary = mg.summary;
        [self.navigationController pushViewController:VC animated:YES];
    }else{
        LSZBigDepartmentVC * vc = [[LSZBigDepartmentVC alloc]init];
        vc.id_id = mg.id_id;
        vc.titleString = mg.name;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end
